﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectCourseContent.aspx.cs"
	Inherits="CourseManager.View.Contents.Student.SelectCourseContent" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>选课页面</title>
	<script type="text/javascript">

		function makeCourseMsg(courseId, teacherName, campus, place, credit, time) {
			return '课程号:&nbsp;&nbsp;&nbsp;' + courseId + '<br/>' +
					'教师:&nbsp;&nbsp;&nbsp;' + teacherName + '<br/>' +
					'学分:&nbsp;&nbsp;&nbsp;' + credit + '<br/>' +
					'时间:&nbsp;&nbsp;&nbsp;' + time + '<br/>' +
					'地点:&nbsp;&nbsp;&nbsp;' + campus + "&nbsp;" + place + "<br/>";
		}

		function DoSelect(courseId, courseName, tId, teacherName, campus, place, credit, time) {
			Ext.net.Notification.show({
				bringToFront: true,
				pinEvent: 'click',
				hideDelay: 3000,
				showPin: true,
				closeVisible: true,
				alignToCfg: {
					offset: [-10, -10],
					position: 'br-br',
					el: Ext.net.getEl('SeletedCourseWindow')
				},
				height: 120,
				width: 200,
				html: makeCourseMsg(courseId, teacherName, campus, place, credit, time),
				title: courseName
			});
		}


		function DoCommand(command, courseId, courseName, tId) {
			var msg = '课程号：&nbsp;&nbsp;&nbsp;' + courseId
					+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>教师号：&nbsp;&nbsp;&nbsp;'
					+ tId + '<br/>课程名：&nbsp;&nbsp;&nbsp;'
					+ courseName + '<br/><br/>选此课程?';
			if (command == "SelectCourse") {
				Ext.Msg.confirm('系统提示', msg, function (btn) {
					if (btn == 'yes') {
						Ext.net.DirectMethods.SelectCourse(courseId, tId, {
							eventMask: {
								showMask: true,
								minDely: 100,
								msg: "请稍候..."
							},
							success: function (result) {
								if (result == false) {
									Ext.Msg.alert('操作失败', '原因可能是课程时间冲突<br/><br/>或者您已选此课程');
								}
							}
						});
					}
				}
				);
				return;
			}

			if (command == 'DeleteCourse') {
				var msg = '课程号：&nbsp;&nbsp;&nbsp;' + courseId
						 + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>教师号：&nbsp;&nbsp;&nbsp;'
						 + tId + '<br/>课程名：&nbsp;&nbsp;&nbsp;'
						 + courseName + '<br/><br/>退此课程?';
				Ext.Msg.confirm('系统提示', msg, function (btn) {
					if (btn == 'yes') {
						Ext.net.DirectMethods.DeleteCourse(courseId, tId, {
							eventMask: {
								showMask: true,
								minDely: 100,
								msg: "正在退课, 请稍候..."
							},
							success: function (result) {
								if (result == true) {
									Ext.Msg.alert('提示', '退课成功');
								}
							}
						});
					}
				});
			}
		}
	</script>
</head>
<body>
	<form runat="server">
	<ext:ResourceManager runat="server" />
	<ext:Store ID="Store" runat="server">
		<Reader>
			<ext:ArrayReader>
				<Fields>
					<ext:RecordField Name="Time" />
					<ext:RecordField Name="Monday" />
					<ext:RecordField Name="Tuesday" />
					<ext:RecordField Name="Wednesday" />
					<ext:RecordField Name="Thursday" />
					<ext:RecordField Name="Friday" />
					<ext:RecordField Name="Saturday" />
					<ext:RecordField Name="Sunday" />
				</Fields>
			</ext:ArrayReader>
		</Reader>
	</ext:Store>
	<ext:Store runat="server" ID="CourseStore">
		<Reader>
			<ext:JsonReader IDProperty="courseId,tId">
				<Fields>
					<ext:RecordField Name="courseId" />
					<ext:RecordField Name="tId" />
					<ext:RecordField Name="courseName" />
					<ext:RecordField Name="teacherName" />
					<ext:RecordField Name="credit" />
					<ext:RecordField Name="time" />
					<ext:RecordField Name="campus" />
					<ext:RecordField Name="place" />
					<ext:RecordField Name="dept" />
					<ext:RecordField Name="capacity" />
				</Fields>
			</ext:JsonReader>
		</Reader>
	</ext:Store>
	<ext:Store runat="server" ID="SelectedCouseStore">
		<Reader>
			<ext:JsonReader IDProperty="courseId,tId">
				<Fields>
					<ext:RecordField Name="tag" />
					<ext:RecordField Name="courseId" />
					<ext:RecordField Name="tId" />
					<ext:RecordField Name="courseName" />
					<ext:RecordField Name="teacherName" />
					<ext:RecordField Name="credit" />
					<ext:RecordField Name="time" />
					<ext:RecordField Name="campus" />
					<ext:RecordField Name="place" />
					<ext:RecordField Name="dept" />
					<ext:RecordField Name="capacity" />
				</Fields>
			</ext:JsonReader>
		</Reader>
	</ext:Store>
	<ext:Window ID="CourseWindow" runat="server" Collapsible="true" Minimizable="true"
		Maximizable="true" Icon="Book" Closable="false" Title="课程查询" Width="860" Height="220"
		X="10" Y="10" CenterOnLoad="false" Layout="Border">
		<Items>
			<ext:GridPanel ID="gridPanel" runat="server" StoreID="CourseStore" StripeRows="true"
				DDGroup="gridPanelDDGroup" Width="860" Height="250" Region="Center" Header="true"
				Margins="5 5 5 5">
				<ColumnModel runat="server">
					<Columns>
						<ext:CommandColumn Width="25" Align="Center">
							<Commands>
								<ext:GridCommand Icon="Add" CommandName="SelectCourse" ToolTip-Text="选此课程" />
							</Commands>
						</ext:CommandColumn>
						<ext:Column Header="课程号" Width="80" DataIndex="courseId" Align="Center" Sortable="false" />
						<ext:Column Header="课程名" Width="150" DataIndex="courseName" Align="Center" Sortable="false" />
						<ext:Column Header="容量" Width="40" DataIndex="capacity" Align="Center" Sortable="false" />
						<ext:Column Header="教师号" Width="60" DataIndex="tId" Align="Center" Sortable="false" />
						<ext:Column Header="教师名" Width="70" DataIndex="teacherName" Align="Center" Sortable="false" />
						<ext:Column Header="学分" Width="40" DataIndex="credit" Align="Center" Sortable="false" />
						<ext:Column Header="时间" Width="200" DataIndex="time" Align="Center" Sortable="false" />
						<ext:Column Header="开课院系" Width="60" DataIndex="dept" Align="Center" Sortable="false" />
						<ext:Column Header="校区" Width="40" DataIndex="campus" Align="Center" Sortable="false" />
						<ext:Column Header="地点" Width="60" DataIndex="place" Align="Center" Sortable="false" />
					</Columns>
				</ColumnModel>
				<SelectionModel>
					<ext:RowSelectionModel runat="server">
					</ext:RowSelectionModel>
				</SelectionModel>
				<BottomBar>
					<ext:PagingToolbar ID="pagingBar" runat="server" PageSize="5" DisplayInfo="true"
						HideRefresh="true" HideLabels="true" Height="30" StoreID="CourseStore">
						<Items>
							<ext:ToolbarSpacer runat="server" Width="10" />
							<ext:TextField runat="server" ID="txtKeywords" EmptyText="输入关键字进行查询，以空格分割   (例:  高等数学 一3-4)"
								Width="350">
								<Listeners>
									<SpecialKey Handler="if(e.getKey() != Ext.EventObject.ENTER) return false;" />
								</Listeners>
								<DirectEvents>
									<SpecialKey OnEvent="BtnSearchClick">
										<EventMask ShowMask="true" Msg="正在查询，请稍候..." />
									</SpecialKey>
								</DirectEvents>
							</ext:TextField>
						</Items>
					</ext:PagingToolbar>
				</BottomBar>
				<Listeners>
					<Command Handler="DoCommand(command, record.data.courseId, record.data.courseName, record.data.tId);" />
				</Listeners>
				<LoadMask ShowMask="true" Msg="正在加载，请稍候..." MsgCls="CourseWindow" />
			</ext:GridPanel>
		</Items>
	</ext:Window>
	<ext:Hidden ID="txtSchedule" runat="server" />
	<ext:Window ID="ScheduleWindow" runat="server" Collapsible="true" Minimizable="true"
		Maximizable="true" Icon="Time" Closable="false" Title="课程表" Width="540" Height="332"
		X="10" Y="240" CenterOnLoad="false" Resizable="false" Layout="Fit">
		<Items>
			<ext:GridPanel ID="scheduleGird" runat="server" StoreID="Store" EnableColumnMove="false"
				DDGroup="scheduleGridDDGroup" EnableColumnResize="false" EnableHdMenu="false"
				StripeRows="true">
				<ColumnModel runat="server">
					<Columns>
						<ext:Column Header="时间" Width="100" DataIndex="Time" Align="Center" Sortable="false" />
						<ext:Column Header="周一" Width="60" DataIndex="Monday" Align="Center" Sortable="false" />
						<ext:Column Header="周二" Width="60" DataIndex="Tuesday" Align="Center" Sortable="false" />
						<ext:Column Header="周三" Width="60" DataIndex="Wednesday" Align="Center" Sortable="false" />
						<ext:Column Header="周四" Width="60" DataIndex="Thursday" Align="Center" Sortable="false" />
						<ext:Column Header="周五" Width="60" DataIndex="Friday" Align="Center" Sortable="false" />
						<ext:Column Header="周六" Width="60" DataIndex="Saturday" Align="Center" Sortable="false" />
						<ext:Column Header="周日" Width="60" DataIndex="Sunday" Align="Center" Sortable="false" />
					</Columns>
				</ColumnModel>
				<SelectionModel>
					<ext:CellSelectionModel>
						<Listeners>
							<CellSelect Handler="var value=#{scheduleGird}.getSelectionModel().getSelectedCell(); var row = value[0], col = value[1],text = #{txtSchedule}.value; if (col > 0 && row >= 0 && text[col * 13 + row] >= 'A') {var id = text.charCodeAt(col * 13 + row)-65; #{SelectedCoursePanel}.getSelectionModel().selectRow(id);}" />
						</Listeners>
					</ext:CellSelectionModel>
				</SelectionModel>
			</ext:GridPanel>
		</Items>
	</ext:Window>
	<ext:Window ID="SeletedCourseWindow" runat="server" Collapsible="true" Minimizable="true"
		Maximizable="true" Icon="Bookmark" Closable="false" Title="已选课程" Width="310"
		Height="332" X="560" Y="240" CenterOnLoad="false" Layout="Fit">
		<Items>
			<ext:GridPanel runat="server" ID="SelectedCoursePanel" StoreID="SelectedCouseStore"
				StripeRows="true" EnableColumnMove="false" EnableHdMenu="false">
				<ColumnModel>
					<Columns>
						<ext:CommandColumn Width="25" Align="Center">
							<Commands>
								<ext:GridCommand Icon="BookDelete" CommandName="DeleteCourse" ToolTip-Text="退课" />
							</Commands>
						</ext:CommandColumn>
						<ext:Column Header="" Width="30" Align="Center" Sortable="false" DataIndex="tag" />
						<ext:Column Header="课程名" Width="110" Align="Center" Sortable="false" DataIndex="courseName" />
						<ext:Column Header="教师" Width="70" Align="Center" Sortable="false" DataIndex="teacherName" />
						<ext:Column Header="学分" Width="40" Align="Center" Sortable="false" DataIndex="credit" />
					</Columns>
				</ColumnModel>
				<Listeners>
					<Command Handler="DoCommand(command, record.data.courseId, record.data.courseName, record.data.tId);" />
				</Listeners>
				<SelectionModel>
					<ext:RowSelectionModel runat="server">
						<Listeners>
							<RowSelect Handler="DoSelect(record.data.courseId, record.data.courseName, record.data.tId, record.data.teacherName, record.data.campus, record.data.place , record.data.credit, record.data.time)" />
						</Listeners>
					</ext:RowSelectionModel>
				</SelectionModel>
			</ext:GridPanel>
		</Items>
	</ext:Window>
	</form>
</body>
</html>
